package com.hujf.netty.example.http;

import com.hujf.netty.example.handle.HttpServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author Hujf
 * @title: ServerInitializer
 * @date 2021/1/29 0029下午 7:12
 * @description: TODO
 */
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        //得到管道
        ChannelPipeline pipeline = ch.pipeline();
        //加入netty提供的httpServerCode
        //1.HttpClientCodec 编解码器
        pipeline.addLast("MyHttpServerCodec",new HttpServerCodec());
        //加入处理器
        pipeline.addLast("MyHttpHandler",new HttpServerHandler());
    }
}
